<template>
  <div class="myContainer">
    <el-row class="myBorderBottom">
      <el-col :span="12" class="myTitleText myLineHeight_40px">设备房运行状态列表</el-col>
      <el-col :span="12" class="myTextAlignRight">
        <!-- <el-button type="primary" class="myBgGreen">告警日志</el-button> -->
      </el-col>
    </el-row>
    <!-- 搜索部分 start -->
    <el-row :gutter="10" class="myPaddingTop_10px">
      <el-col :span="6">
        <template>
           <el-cascader
            placeholder="全部项目/小区"
            :options="regionOptions"
            v-model="regionOptSelected"
            ></el-cascader>
        </template>
      </el-col>
      <el-col :span="4">
        <template>
          <el-select v-model="devRoomStatusSelected"
            clearable
            placeholder="全部运行状态">
            <el-option
              v-for="item in Object.keys(devRoomStatusType)"
              :key="devRoomStatusType[item]"
              :label="devRoomStatusType[item]"
              :value="item">
            </el-option>
          </el-select>
        </template>
      </el-col>
      <el-col :span="4">
        <template>
          <el-select v-model="devRoomTypeSelected" 
          clearable
          placeholder="全部设备房类型">
            <el-option
              v-for="item in Object.keys(devRoomTypeList)"
              :key="devRoomTypeList[item]"
              :label="devRoomTypeList[item]"
              :value="item">
            </el-option>
          </el-select>
        </template>
      </el-col>
      <el-col :span="4">
        <el-button @click="handleSearchClick" type="primary" class="myBgGreen">查询</el-button>
      </el-col>
    </el-row>
    <!-- 搜索部分 end -->
    <el-row class="mymarginTop_10px">
      <el-col :span="24">
        <template>
          <el-table
            border
            :data="list"
            :stripe = true
            v-loading="loading"
            style="width: 100%">
            <el-table-column
              label="序号"
              type="index"
              width="100">
            </el-table-column>
            <el-table-column
              label="设备房名称"
              prop="dev_room_name">
            </el-table-column>
            <el-table-column
              label="设备房类型"
              prop="dev_room_type">
              <template scope="scope">
                <span>{{scope.row.dev_room_type | devRoomType}}</span>
              </template>
            </el-table-column>
            <el-table-column
              label="设备房运行状态"
              width="130"
              prop="alarm_status">
              <template scope="scope">
                <!-- <span>{{scope.row.alarm_status | alarmStatus}}</span> -->
                <span v-if="scope.row.alarm_status==0">正常</span>
                <span v-if="scope.row.alarm_status==1" style="color: rgb(255,169,46);">告警</span>
                <span v-if="scope.row.alarm_status==2" style="color: #f00;">严重告警</span>
              </template>
            </el-table-column>
            <el-table-column
              label="责任人"
              width="120"
              prop="duty_user_name">
            </el-table-column>
            <el-table-column
              label="联系电话"
              width="130"
              prop="duty_user_phone">
            </el-table-column>
            <el-table-column
              label="设备房物理地址"
              prop="display_room_name">
            </el-table-column>
            <el-table-column
              label="所属小区"
              prop="area_name">
            </el-table-column>
            <el-table-column
              label="功能操作"
              width="100">
              <template scope="scope">
                <el-button class="look" type="text" size="small" @click="onDetailed(scope.row.dev_room_id, scope.row.duty_user_name, scope.row.duty_user_phone, scope.row.dev_room_name)">详情</el-button>
              </template>
            </el-table-column>
          </el-table>
        </template>
      </el-col>
    </el-row>
    <!-- 分页控件 start -->
    <div class="block">                    
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="page_num"
        :page-sizes="[10, 15]"
        :page-size="page_size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </div>
    <!-- 分页控件 end -->
  </div>
</template>  

<style scoped>
  .myContainer{
    background: #fff;
    padding: 10px;
  }
  .myHeadeTitle{
    color: #000;
    font-weight: 500;
    font-size: 16px;
    padding-bottom: 10px;
    border-bottom: 1px solid #dbdbdb;
    margin-bottom:10px; 
  }
  .myHeadeTitle:before,.myHeadeTitle:after{
    content: " ";
    display: block;
    clear: both;
  }
  .myBgGreen{
    background: #00c2a9;
    border-color: #00c2a9;
    color: #fff;
    margin-top: 2px;
  }
  .myLineHeight_35px{
    line-height: 35px;
  }
  .myTextAlignRight{
    text-align: right;
  }
  .myBgGreen:hover{
    background: #33ceba;
  }
  .myPaddingTop_10px{
    padding-top: 10px;
  }  
  .myLeftMsg{
    line-height: 40px;
    text-align: right;
    padding-right: 10px;
  }
  .myPaddingBottom_10px{
    padding-bottom: 10px;
  }
  .myVA_M{
    vertical-align: middle;
  }
  .myPadding_20px{
    padding: 20px;
  }    
  .myTitleText{
    font-weight: 500;
    font-size: 16px;
  }
  .myLineHeight_40px{
    line-height: 40px;
  }
  .myBorderBottom{
    border-bottom:1px solid #dbdbdb;
  }
  .mymarginTop_10px{
    padding-top: 10px;
  }
</style>

<script>
import { extractAreaIds } from '@/utils/misc';
import { getRegion } from '@/utils/localstorage';
import { devRoomTypeList } from '@/api/dev_room';
import { getDevRoomStatus, devRoomStatusType } from '@/api/dev_monitor';

  export default {
     data(){
      return{
        title:"运行状态",
        // 列表
        loading: false,
        list: [],
        page_num:1,
        page_size:10,
        total:null,

        // 搜索条件
        // 小区选择
        regionOptions: [],
        regionOptSelected: [],

        kw: "",
        devRoomTypeSelected: null,
        devRoomTypeList: devRoomTypeList,
        devRoomStatusType: devRoomStatusType,
        devRoomStatusSelected: null,

        // housValue:"",
        // housOptions:[],
        // value1:"",
        // tableData:[]
      }
    },
    computed: {
      areaIds() {
        return extractAreaIds(this.regionOptSelected, this.regionOptions);
      }
    },
     filters: {
      devRoomType(value) {
        return devRoomTypeList[value];
      },
      alarmStatus(value) {
        return devRoomStatusType[value];
      }
    },
    created(){
      document.title=this.title;
      this.regionOptions = getRegion();
      this.regionOptSelected.push(this.regionOptions[0].value,this.regionOptions[0].children[0].value,this.regionOptions[0].children[0].children[0].value);
      
      this.fetchList();
    },
    methods:{
      fetchList() {
        let vm = this;
        let params = {
          kw: vm.kw,
          dev_room_type: vm.devRoomTypeSelected,
          page_num: vm.page_num,
          page_size: vm.page_size
        };

        vm.loading = true;
        getDevRoomStatus(vm.areaIds, params)
        .then(response => {
          let res = response.data;
          vm.list = res.rows;
          vm.page_num = res.page_num;
          vm.page_size = res.page_size;
          vm.total = res.total;

          vm.loading = false;
        })
        .catch(error => {
          vm.loading = false;
        })
      },
      handleSizeChange(val) {//每页条数控制
        this.page_size = val;
        this.fetchList();
      },
      handleCurrentChange(val) {//每页
        this.page_num = val;
        this.fetchList();
      },
      handleSearchClick() {
        this.fetchList();
      },
      onDetailed(id, dutyName, dutyPhone, devRoomName){
          this.$router.push({
            path:'/yxztInfor',
            query: {
              id: id, 
              dutyName: dutyName,
              dutyPhone: dutyPhone,
              devRoomName: devRoomName
            }
          })        
      }
    }

  }

</script>  



